package com.huiyun.project.im.api.client.feign;


import com.huiyun.project.common.core.domain.R;
import com.huiyun.project.im.api.client.vo.req.app.ImAppReq;
import com.huiyun.project.im.api.client.vo.req.tenant.ImTenantMessageReq;
import com.huiyun.project.im.api.client.vo.req.tenant.ImTenantsReq;
import com.huiyun.project.im.api.client.vo.req.tenant.ImUserCsReq;
import com.huiyun.project.im.api.client.vo.req.user.ImUserReq;
import com.huiyun.project.im.api.client.vo.resp.ImAppResp;
import com.huiyun.project.im.api.client.vo.resp.ImTenantResp;
import com.huiyun.project.im.api.client.vo.resp.ImUserResp;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;

import java.util.List;

/**
 * im sp对外 feign接口
 */
@FeignClient(contextId = "remoteApiImSpService", value = "huiyun-im-server-biz")
public interface RemoteApiImSpService {


    /**
     * 批量创建更新im租户
     * 没有就新增
     * 有就更新
     *
     * @param version         版本号
     * @param tenantCreateReq
     * @param
     * @return
     */
    @PostMapping(value = "im/api/sp/{version}/tenants", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = "application/json;charset=UTF-8")
    R<List<ImTenantResp>> tenants(@PathVariable("version") String version,
                                  @RequestBody List<ImTenantsReq> tenantCreateReq
            , @RequestHeader("ImAuthorization") String token
    );

    /**
     * 批量创建更新子账户
     * 没有就新增
     * 有就更新
     *
     * @param version     版本号
     * @param userAddList
     * @param
     */
    @PostMapping(value = "im/api/sp/{version}/users/{tenantId}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = "application/json;charset=UTF-8")
    R<List<ImUserResp>> tenantUsers(@PathVariable("version") String version,
                                    @PathVariable("tenantId") String tenantId,
                                    @RequestBody List<ImUserReq> userAddList,
                                    @RequestHeader("ImAuthorization") String token
    );

    /**
     * 单个创建或更新个人租户
     * 没有就新增
     * 有就更新
     *
     * @param version 版本号
     * @param req
     * @param
     * @return
     */
    @PostMapping(value = "im/api/sp/{version}/user", produces = MediaType.APPLICATION_JSON_VALUE, consumes = "application/json;charset=UTF-8")
    R<ImUserResp> user(@PathVariable("version") String version,
                       @RequestBody ImUserReq req
            , @RequestHeader("ImAuthorization") String token
    );


    /**
     * 客服授权账号修改等
     *
     * @param version 版本号
     * @param req
     * @param
     */
    @PostMapping(value = "im/api/sp/{version}/user/cs/{tenantId}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = "application/json;charset=UTF-8")
    R<List<ImUserResp>> updateUserCs(@PathVariable("version") String version,
                                   @PathVariable("tenantId") String tenantId,
                                   @RequestBody ImUserCsReq req,
                                   @RequestHeader("ImAuthorization") String token
    );

    /**
     * 子账号删除
     *
     * @param version 版本号
     * @param bidList 业务系统id集合
     * @param
     */
    @PostMapping(value = "im/api/sp/{version}/delete/{tenantId}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = "application/json;charset=UTF-8")
    R<List<String>> deleteUsers(@PathVariable("version") String version,
                                @PathVariable("tenantId") String tenantId,
                                @RequestBody List<String> bidList,
                                @RequestHeader("ImAuthorization") String token
    );


    /**
     * 通过租户发送消息
     *
     * @param version          版本号
     * @param tenantMessageReq
     * @param
     * @return Map<username, tenantId> 返回发送成功的用户id
     */
    @PostMapping(value = "im/api/sp/{version}/notice/sendMessage", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = "application/json;charset=UTF-8")
    R<List<String>> sendNoticeMessage(@PathVariable("version") String version,
                                      @RequestBody ImTenantMessageReq tenantMessageReq
            , @RequestHeader("ImAuthorization") String token
    );


    /**
     * 通过应用key查询应用信息LoginReq
     *
     * @param version 版本号
     * @param
     */
    @PostMapping(value = "im/api/sp/{version}/app/getByAppKey")
    R<ImAppResp> getByAppKey(@PathVariable("version") String version,
                             @RequestBody ImAppReq imAppReq, @RequestHeader("ImAuthorization") String token
    );
}
